<?php

namespace app\admin\model;

class AdEquip extends BaseModel
{
    protected $name = 'ad_equip';

    public function formatInfo($info)
    {
        $info['organization_name'] = $info->school->name;
        $info['scene_name']        = $info->scene->name;
        $info['resource']          = json_decode($info->resource, true);
        $info['online']            = (int)(time() - $info['device_update'] < 300);

        return $info;
    }

    public function school(): \think\model\relation\HasOne
    {
        return $this->hasOne(School::class, 'id', 'organization');
    }

    public function scene(): \think\model\relation\HasOne
    {
        return $this->hasOne(SiteScene::class, 'id', 'scene_id');
    }
}